import java.util.ArrayList;

public class GeneticAlgorithmIndividual {
	// Format:
	// polynomialCoefficients.get(0)+polynomialCoefficients.get(1)+polynomialCoefficients.get(2)+...+sineCoefficient*sin(x*sineCoefficient2)

	ArrayList<Double> polynomialCoefficients;
	double sineCoefficient, sineCoefficient2;

	public GeneticAlgorithmIndividual(ArrayList<Double> polynomialCoefficients,
			double sineCoefficient, double sineCoefficient2) {
		this.polynomialCoefficients = polynomialCoefficients;
		this.sineCoefficient = sineCoefficient;
		this.sineCoefficient2 = sineCoefficient2;
	}

	public double getValue(int day) {
		double value = 0;

		for (int i = 0; i < polynomialCoefficients.size(); i++) {
			value += polynomialCoefficients.get(polynomialCoefficients.size()
					- 1 - i)
					* Math.pow(day, i);
		}
		value += sineCoefficient * Math.sin(day * sineCoefficient2);

		return value;
	}

	public static GeneticAlgorithmIndividual generate() {
		Double sine, sine2;
		ArrayList<Double> coefficients = new ArrayList<Double>();
		if (Math.random() > 0.5) {
			coefficients.add(Math.random() * 1000000 - 500000);
		}
		sine = Math.random() * 1000000 - 500000;
		sine2 = Math.random() * 1000000 - 500000;
		return new GeneticAlgorithmIndividual(coefficients, sine, sine2);
	}
}